<template>
  <el-card>
    <el-form inline class="category-three" :disabled="isDisable">
      <el-form-item label="一级分类">
        <el-select
          v-model="category.category1Id"
          placeholder="请选择一级分类"
          @change="id1Change"
        >
          <el-option
            v-for="item in category.category1List"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="二级分类">
        <el-select
          v-model="category.category2Id"
          placeholder="请选择二级分类"
          @change="id2Change"
        >
          <el-option
            v-for="item in category.category2List"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="三级分类">
        <el-select v-model="category.category3Id" placeholder="请选择三级分类">
          <el-option
            v-for="item in category.category3List"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          >
          </el-option>
        </el-select>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<script>
import { mapActions, mapState } from 'vuex'
export default {
  name: 'CategoryThree',
  props: {
    isDisable: {
      type: Boolean,
      require: true,
      default: false
    }
  },
  computed: {
    ...mapState('category', ['category'])
  },
  mounted() {
    this.getCategory1Id()
  },

  beforeDestroy() {
    this.resetStore()
  },
  methods: {
    ...mapActions('category', [
      'getCategory1Id',
      'getCategory2Id',
      'getCategory3Id',
      'resetStore'
    ]),
    id1Change() {
      this.getCategory2Id()
    },
    id2Change() {
      this.getCategory3Id()
    }
  }
}
</script>

<style>
.category-three .el-form-item {
  margin: 10px 40px;
}
</style>
